package cn.edu.scau.cmi.chenbingquan.client;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.chenbingquan.spring.domain.Student;
import cn.edu.scau.cmi.chenbingquan.spring.domain.Teacher;
import cn.edu.scau.cmi.chenbingquan.spring.util.ApplicationContextUtil;

public class SingletonApplicationContextUtilClient {
		private static Teacher liangzaoqing;
		private static Student zhangsan;

		public SingletonApplicationContextUtilClient() {
			
		}

		public static void main(String[] args) {
			ApplicationContext ac = getApplicationContext();
			zhangsan = (Student)ac.getBean("zhangsan");		// 配置id为zhangsan的bean,通过反射构造对象
			liangzaoqing = (Teacher)ac.getBean("liangzaoqing");
			liangzaoqing.setName("liang");
			zhangsan.setName("zhangsan");
			zhangsan.setTutor(liangzaoqing);
			System.out.println(zhangsan.getName() + "的毕业设计指导导师是：" + zhangsan.getTutor().getName());
		}

		private static ApplicationContext getApplicationContext() {
			ApplicationContext applicationContext = ApplicationContextUtil.getApplicationContext();
			return applicationContext;
		}
}
